using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace MultiTCPProxy.Models
{
    /// <summary>
    /// TCP代理配置模型类
    /// </summary>
    public class ProxyConfig
    {
        [JsonPropertyName("name")]
        public string Name { get; set; }

        [JsonPropertyName("listenPort")]
        public int ListenPort { get; set; }

        [JsonPropertyName("targetIP")]
        public string TargetIP { get; set; }

        [JsonPropertyName("targetPort")]
        public int TargetPort { get; set; }

        [JsonPropertyName("enabled")]
        public bool Enabled { get; set; }

        [JsonPropertyName("description")]
        public string Description { get; set; }

        public static string Serialize(List<ProxyConfig> configs)
        {
            var options = new JsonSerializerOptions
            {
                WriteIndented = true,
                Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
            };
            return JsonSerializer.Serialize(configs, options);
        }

        public static List<ProxyConfig> Deserialize(string json)
        {
            var options = new JsonSerializerOptions
            {
                Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
            };
            return JsonSerializer.Deserialize<List<ProxyConfig>>(json, options);
        }
    }
}